package com.ayuku.commons;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;

/**
 * 
 * @author putu kusuma <putukn@gmail.com>
 *
 */
public class ListHelp extends org.eclipse.swt.widgets.Dialog {

	private Shell dialogShell;
	public StyledText txtHelp;
	public String stringHelp;
	

	

	public String getStringHelp() {
		return stringHelp;
	}

	public void setStringHelp(String stringHelp) {
		this.stringHelp = stringHelp;
	}

	public StyledText getTxtHelp() {
		return txtHelp;
	}

	public void setTxtHelp(StyledText txtHelp) {
		this.txtHelp = txtHelp;
	

	}

	/**
	* Auto-generated main method to display this 
	* org.eclipse.swt.widgets.Dialog inside a new Shell.
	*/
	public static void main(String[] args) {
		try {
			Display display = Display.getDefault();
			Shell shell = new Shell(display);
			ListHelp inst = new ListHelp(shell, SWT.NULL);
			inst.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public ListHelp(Shell parent, int style) {
		super(parent, style);
	}

	public void open() {
		try {
			Shell parent = getParent();
			dialogShell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

			dialogShell.setLayout(new FormLayout());

			txtHelp = new StyledText(dialogShell, SWT.RESIZE | SWT.V_SCROLL | SWT.H_SCROLL);
			FormData txtHelpLData = new FormData();
			txtHelpLData.left =  new FormAttachment(0, 1000, 12);
			txtHelpLData.top =  new FormAttachment(0, 1000, 5);
			txtHelpLData.width = 507;
			txtHelpLData.height = 339;
			txtHelpLData.right =  new FormAttachment(1000, 1000, -5);
			txtHelpLData.bottom =  new FormAttachment(1000, 1000, -5);
			txtHelp.setLayoutData(txtHelpLData);

			txtHelp.setText("\n* Gunakan tombol Tambah  untuk menambah data baru.\n\n* Gunakan tombol Edit untuk menampilkan detail dari baris tersebut dan/atau mengedit.\n\n* Gunakan tombol Hapus untuk menghapus data, pilih data yang dihapus.\n\n* Gunakan tombol Refresh untuk memuat ulang data yang terbaru.\n\n* Gunakan kotak Search untuk mencari data yg diinginkan.\n\n* Gunakan tombol Reset untuk menampilkan kembali keseluruhan data.\n");
			
			if (stringHelp != null && stringHelp.trim().length()>1){
				txtHelp.setText(stringHelp);	
			}
			txtHelp.setEditable(false);
			//txtHelp.setEnabled(false);

			dialogShell.layout();
			dialogShell.pack();			
			dialogShell.setSize(550, 250);
			dialogShell.setBackground(SWTResourceManager.getColor(255, 255, 255));
			dialogShell.setText("Petunjuk");
			dialogShell.setLocation(getParent().toDisplay(100, 100));
			txtHelp.setForeground(SWTResourceManager.getColor(0, 0, 255));
			dialogShell.open();
			Display display = dialogShell.getDisplay();
			while (!dialogShell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
